package com.by.ui;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.by.and_widget.NineGridLayout;

/**
 * Created by admin on 2016/5/13.
 */
public class NineGridActivity extends Activity {
    private NineGridLayout mLayout;
    private int count = 2;
    private BaseAdapter mAdapter = new BaseAdapter() {
        @Override
        public int getCount() {
            return count;
        }

        @Override
        public Object getItem(int i) {
            return null;
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }

        @Override
        public View getView(int i, View p, ViewGroup viewGroup) {
            ImageView view = new ImageView(NineGridActivity.this);
            view.setScaleType(ImageView.ScaleType.FIT_XY);
            view.setImageResource(R.drawable.dd);
            return view;
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_nine_grid);
        mLayout = (NineGridLayout) findViewById(R.id.nine_grid_layout);
        mLayout.setBackgroundColor(Color.RED);

        mLayout.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                int[] location = new int[2];
                view.getLocationOnScreen(location);
                int width = view.getWidth();
                int height = view.getHeight();
                Log.e("TAG", i + ",left:" + location[0] + ",top:" + location[1] + ",width:" + width + ",height:" + height);
                Intent intent = new Intent(NineGridActivity.this, BigPicActivity.class);
                intent.putExtra("left", location[0]);
                intent.putExtra("top", location[1]);
                intent.putExtra("width", width);
                intent.putExtra("height", height);
                startActivity(intent);
            }
        });
        mLayout.setAdapter(mAdapter);

        findViewById(R.id.btn_num).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (count <= 9) {
                    count++;
                } else {
                    count = 1;
                }
                mAdapter.notifyDataSetChanged();
            }
        });
    }

    @Override
    public void startActivity(Intent intent) {
        super.startActivity(intent);
        overridePendingTransition(0, 0);
    }

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(0, 0);
    }
}
